package cn.wolfcode.wolf2w.redis.util;


import cn.wolfcode.wolf2w.util.Consts;
import lombok.Getter;

/**
 * redis 的 key管理工具类
 * 约定: 一个枚举实例就是一个key
 */
@Getter
public enum RedisKeys {

    //接口防刷key
    BRUSH_PROOF("brush_proof", 60L),


   //用户攻略点赞key
    USER_STRATEGY_THUMB("user_strategy_thumb", -1L),

    //用户攻略收藏
    USER_STRATEGY_FAVOR("user_strategy_favor", -1L),



    //攻略统计对象
    STRATEGY_STATIS_VO("strategy_statis_vo", -1L),



    //用户登录key shift + ctrl + u
    USER_LOGIN_TOKEN("user_login_token", Consts.USER_INFO_TOKEN_VAI_TIME * 60L),

    //短信验证码
    VERIFY_CODE("verify_code", Consts.VERIFY_CODE_VAI_TIME * 60L);

    private String prefix;  //redis的key前缀
    private Long time;  //redis的key的有效时间, -1L表示不需要指定过期时间,单位秒

    private RedisKeys(String prefix, Long time){
        this.prefix = prefix;
        this.time = time;
    }
    //拼接完整的redis key
    public String join(String... values){
        StringBuilder sb = new StringBuilder(80);
        sb.append(this.prefix);
        for (String value : values) {
            sb.append(":").append(value);
        }
        return  sb.toString();
    }
    public static void main(String[] args) {
        System.out.println(RedisKeys.VERIFY_CODE.join("13700000000", "xx", "yy"));
    }

}
